<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>经纪人注册</title>
    <!-- 引入 WeUI -->
    <link rel="stylesheet" href="/static/css/weui.min.css"/>
    <link rel="stylesheet" href="/static/css/wx.css"/>
</head>
<body>

<div class="page">

    <form id="apply_form">

    <input type="hidden" name="shopId" value="${apply.shopId}"/>
    <input type="hidden" name="openId" value="${apply.openId}"/>

    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="name" type="text" placeholder="请输入姓名"/>
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">所属门店</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="shopName" type="text" value="${apply.shopName}" readonly/>
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">工号</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="staffId" type="text" placeholder="请填写工号" />
            </div>
        </div>
    </div>

    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd">
                <label for="" class="weui-label">手机号</label>
            </div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="phone" type="tel" placeholder="请输入手机号"/>
            </div>
        </div>
        <div class="weui-cell weui-cell_vcode">
            <div class="weui-cell__hd"><label class="weui-label">验证码</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" name="validateCode" type="number" placeholder="请输入验证码"/>
            </div>
            <div class="weui-cell__ft">
                <button type="button" class="weui-vcode-btn vcode-btn">获取验证码</button>
            </div>
        </div>
    </div>

    </form>
    <div class="weui-btn-area">
        <a class="weui-btn weui-btn_primary" href="javascript:void(0);" id="submitBtn">提交</a>
    </div>

</div>

<div id="loadingToast" class="weui-actionsheet_toggle">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">提交中</p>
    </div>
</div>

</body>

<script type="text/javascript" src="/static/js/zepto.min.js"></script>
<script type="text/javascript">


    $(function(){
        var $page = $('#loadingToast');

        function hidenTags() {
            $page.addClass('weui-actionsheet_toggle');
            $page.fadeOut(200);
        }


        function showTags(){
            $page.removeClass('weui-actionsheet_toggle');
            $page.fadeIn(200);
        }

        var validateCodeFlag = false;

        $(".vcode-btn").click(function(){
            validateCodeFlag = true;
            $(this).css("color","#c8c8cd");
            $(this).html("正在发送");
        });

        $("#submitBtn").on("click", function(){

            var name = $("#apply_form").find("input[name=name]").val();
            if (name == null || name.trim() == "") {
                alert("请输入姓名。");
                return;
            }

            var staffId = $("#apply_form").find("input[name=staffId]").val();
            if (staffId == null || staffId.trim() == "") {
                alert("请输入工号。");
                return;
            }

            var phone = $("#apply_form").find("input[name=phone]").val();
            if (phone == null || phone.trim() == "") {
                alert("请输入手机号。");
                return;
            }

            if (!validateCodeFlag) {
                alert("请先发送验证码。");
                return;
            }

            var validateCode = $("#apply_form").find("input[name=validateCode]").val();
            if (validateCode == null || validateCode.trim() == "") {
                alert("请输入验证码。");
                return;
            }

            showTags();

            var url = "/api/agent/apply/submit";
            var param = $("#apply_form").serialize();
            $.post(url,param,function(data){
                hidenTags();

                if (data == 1) {
                    window.location.href="/agent/apply_success"
                } else if (data == -10) {
                    alert("账号异常。");
                } else {
                    alert("系统异常。");
                }

            });



            $page.removeClass('weui-actionsheet_toggle');
            $page.fadeIn(200);
        });
    });




</script>
</html>